package com.haoxin.ai_course.modules.controller;

import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.R;
import com.haoxin.ai_course.common.utils.WeChatUtil;
import com.haoxin.ai_course.modules.course.entity.VO.H5Statistics;
import com.haoxin.ai_course.modules.sys.service.H5StatisticsService;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;



/**
 * 字典数据表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-03-25 11:30:40
 */
@RestController
@AllArgsConstructor
@Api(value="api",tags="数据统计")
@RequestMapping("/h5Statistics")
public class AdminDataReportController  extends AbstractController {
	final H5StatisticsService h5StatisticsService;
	@PostMapping("saveCount")
	public R saveCount(@Param("statisticsType")Integer statisticsType){
		H5Statistics h5Statistics = h5StatisticsService.getById(1);
		if(h5Statistics == null) {
			h5Statistics = new H5Statistics();
			h5Statistics.setId(1);
		}
		switch(statisticsType) {
		case 1://按钮点击
			h5Statistics.setButtonHitCount(h5Statistics.getButtonHitCount()+1);
			break;
		case 2://h5点击
			h5Statistics.setH5HitCount(h5Statistics.getH5HitCount()+1);
			break;
		case 3://h5分享点击
			h5Statistics.setShareCount(h5Statistics.getShareCount()+1);
			break;
		}
		h5StatisticsService.saveOrUpdate(h5Statistics);
		return R.ok();
	}
	@GetMapping("showCountResult")
	public R showCountResult(){
		H5Statistics h5Statistics =h5StatisticsService.getById(1);
		return R.ok().put("data", h5Statistics);
	}
	
}
